package round82;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

/**
 * User: Samuel
 * Date: 08-05-11
 * Time: 03:16 PM
 */
public class C {

    public static void main(String[] args) throws IOException {
        new C().solve();
    }

    int c0, d0;
    int[][] stuff;
    int[][] cache;

    private void solve() throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String[] split = in.readLine().split(" ");
        int n, m;
        n = Integer.parseInt(split[0]);
        m = Integer.parseInt(split[1]);
        c0 = Integer.parseInt(split[2]);
        d0 = Integer.parseInt(split[3]);
        m++;
        stuff = new int[m][4];
        stuff[0][0] = 0;
        stuff[0][1] = 0;
        stuff[0][2] = c0;
        stuff[0][3] = d0;

        for (int i = 1; i < m; i++) {
            split = in.readLine().split(" ");
            stuff[i][0] = Integer.parseInt(split[0]);
            stuff[i][1] = Integer.parseInt(split[1]);
            stuff[i][2] = Integer.parseInt(split[2]);
            stuff[i][3] = Integer.parseInt(split[3]);
        }

        cache = new int[n + 1][m + 1];
        for (int i = 0; i < cache.length; i++) {
            Arrays.fill(cache[i], -1);
        }
        int ans = getMax(n, 0);
        System.out.println(ans);
    }

    private int getMax(int res, int ind) {
        if (res <= 0 || ind >= stuff.length)
            return 0;
        if (cache[res][ind] != -1) {
            return cache[res][ind];
        }

        int max = -1;
        for (int i = 0; i <= Math.min((ind == 0 ? 100000000 : stuff[ind][0] / stuff[ind][1]), res / stuff[ind][2]); i++) {
            max = Math.max(max, stuff[ind][3] * i + getMax(res - i * stuff[ind][2], ind + 1));
        }
        cache[res][ind] = max;
        return cache[res][ind];
    }

}
